package com.teamwe.movecard.repository;

import com.teamwe.movecard.domain.Problem;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface ProblemRepository extends CrudRepository<Problem, Integer> {

    /**
     * 随即抽取对应年级的10道题目
     * @param grade
     * @return
     */
    @Query(value = "select  * from problem where grade = :grade order by rand() limit 10", nativeQuery = true)
    public List<Problem> getRandomProblemList(@Param("grade") String grade);

    /**
     * 批量删除题目
     * @param list
     */
    @Modifying
    @Transactional
    @Query(value = "delete from problem where pro_id in (?1)", nativeQuery = true)
    public void batchDeletion(List<Integer> list);
}
